<?

function check_plugin_access($id, $plug, $backref = "")
{
  global $msg;

  if (!$plug)
  {
    print "<br>\n";
    print "{$msg["PlugNotFound"]}&nbsp;(id = $id)<br>\n";
    if ($backref <> "")
    {
      print "<a href=\"$backref\">{$msg["Continue"]}</a><br>\n";
    }
    print "<br>\n";
    return False;
  }

  return True;
}


function check_plugin_edit_access($id, $plug, $backref = "")
{
  global $msg;
  global $user;

  if (!check_plugin_access($id, $plug, $backref))
    { return False; }

  if (($plug["owner"] <> $user["id"]) && (!$user["admin"]))
  {
    print "<br>\n";
    print "{$msg["AccessDenied"]}&nbsp;(id = $id)<br>\n";
    if ($backref <> "")
    {
      print "<a href=\"$backref\">{$msg["Continue"]}</a><br>\n";
    }
    print "<br>\n";
    return False;
  }

  return True;
}


function translate_tags($plugtags, $tags_n)
{
  $str = "";

  $tags = explode("|", $plugtags);

  $n = count($tags);
  for ($i = 0; $i < $n; $i++) 
  {
    $tag = strtr($tags_n[$tags[$i]], array(" "=>"&nbsp;"));
    if ($tag)
    {
      $str .= (($str) ? ", " : "").$tag;
    }
  }

  return $str;
}


//-----------------------------------------------------------------------------

function print_plug($plug, $ref="")
{
  print "<div>\n";
  if ($ref) 
  {
    print "<a href=\"$ref\"><b>{$plug["name"]}</b></a>";
  }
  else
  {
    print "<b>{$plug["name"]}</b>";
  }
  $descr = extract_lang_str($plug["description"]);
  print "<br>&nbsp;&nbsp;{$descr}\n";
  print "</div>\n";
}


//-----------------------------------------------------------------------------


function print_plug_wide($plug, $ref="")
{
  global $msg, $tags1, $tags2;

  datetime_to_date_time($plug["update_date"], $date, $time);
  $time = ($time && ($time <> "00:00")) ? "[".$time."]" : "";

  $descr = extract_lang_str($plug["description"]);
  $compat = translate_tags($plug["tags"], $tags1);
  $labels = translate_tags($plug["tags"], $tags2);

  if ($plug["votes_count"]) 
  {
    $rating = "<b>".number_format($plug["rating"], 1)."</b> / ".$plug["votes_count"];
  } 
  else 
  {
    $rating = "--";
  }

?>

<!-- Plugin -->

<div class="plug_info">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
  <td valign="top">
    <a class="name_ref" href="<?=$ref?>"><?=$plug["name"];?></a><br>
    &nbsp;&nbsp;<?=$descr;?>

  </td>

  <td valign="top" width="300" rowspan="2">
    <table border="0" width="100%">
     <tr><td class="comment" width="100" align="right"><?=$msg["PlugAuthor"]?>&nbsp;</td> <td> <a class="info_ref" href="user?id=<?=$plug["owner"]?>"><?=$plug["author"]?></a></td></tr>
     <tr><td class="comment" width="100" align="right"><?=$msg["Updated"]?>&nbsp;</td> <td> <?=$date?> <small><?=$time?></small></td></tr>
     <tr><td class="comment" width="100" align="right"><?=$msg["PlugRating"]?>&nbsp;</td> <td> <?=$rating?> </td></tr>
    </table>
  </td>
</tr>

<tr>
  <td>
    <span class="tag_comment"><?=$msg["PlugLabels"]?></span> <span class="tag_label"><?=$labels?></span> &nbsp;|&nbsp;
    <span class="tag_comment"><?=$msg["PlugCompat"]?></span> <span class="tag_compat"><?=$compat?></span>
  </td>
  <td>
  </td>
</tr>
</table>
</div>

<?
}


//-----------------------------------------------------------------------------

function print_plug_ex($plug)
{
  global $msg;

  $descr = extract_lang_str($plug["description"]);
  $comment = extract_lang_str($plug["comment"]);

  print "\n<!-- Plugin -->\n";

  print "<div class=\"plug_info1\">\n";
  print "<div class=\"plug_info1_in\">\n";

  print "<span class=\"info_name\">{$plug["name"]}</span>\n";
  print "<span class=\"info_descr\">{$descr}</span>\n";

  if ($plug["author"])
  {
    print "<span class=\"info_prompt\">{$msg["PlugAuthor"]}</span>\n";
    print "<span class=\"info_text\">{$plug["author"]}</span>\n";
  }

  if ($plug["homepage"])
  {
    print "<span class=\"info_prompt\">{$msg["PlugHomePage"]}</span>\n";
    print "<span class=\"info_text\"><a href=\"{$plug["homepage"]}\">{$plug["homepage"]}</a></span>\n";
  }

  if ($comment)
  {
    print "<span class=\"info_prompt\">{$msg["Comment"]}</span>\n";
    print "<span class=\"info_comment\">";
    print nl2br($comment);
    print "</span>\n";
  }

  print "</div>\n";
  print "</div>\n";
}



function print_plug_update($info)
{
  datetime_to_date_time($info["date"], $date, $time);
  $text = extract_lang_str($info["text"]);

  $time = ($time && ($time <> "00:00")) ? "[".$time."]" : "";
  print "<!-- update -->\n";
  print "<div class=\"news_date\"><b>$date</b> <small>$time</small></div>\n";
  print "<div style=\"margin:5px 0px 0px 10px\">\n";
  print nl2br($text)."\n";
  print "</div>\n";
}


function print_plug_comment($info, $printtext=True)
{
  datetime_to_date_time($info["date"], $date, $time);
  $time = ($time && ($time <> "00:00")) ? "[".$time."]" : "";

  $user = $info["fullname"];
  if (!$user)
    { $user = $info["name"]; }
  if (!$user)
    { $user = "UserID=".$info["user"]; }

  print "<!-- comment -->\n";
  print "<span class=\"news_date\"><b>$date</b> <small>$time</small>,</span>\n";

  print "<a href=\"user?id={$info["user"]}\">{$user}</a>\n";

  if ($printtext)
  {
    print "<div style=\"margin:5px 0px 0px 10px\">\n";
    print nl2br($info["text"])."<br>\n";
    print "</div>\n";
  }
}

?>